package com.winshare.saleAssistant.controller;

import com.winshare.saleAssistant.domain.dto.req.*;
import com.winshare.saleAssistant.service.BannerService;
import com.winshare.saleAssistant.util.LogicResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/sys/banner")
@CrossOrigin
@Api(value = "轮播图管理", description = "轮播图管理")
public class BannerController {

    private final BannerService bannerService;

    public BannerController(BannerService bannerService) {
        this.bannerService = bannerService;
    }

    @PostMapping("/save")
    @ApiOperation(value = "新增Banner接口",notes = "新增banner接口")
    public LogicResponse save(@RequestBody @Validated BannerCreateDTO bannerCreateDTO) {
        bannerService.save(bannerCreateDTO);
        return LogicResponse.success("success");
    }

    @PostMapping("/update")
    @ApiOperation(value = "修改Banner接口", notes = "修改Banner接口")
    public LogicResponse update(@RequestBody @Validated BannerUpdateDTO bannerUpdateDTO) {
        bannerService.update(bannerUpdateDTO);
        return LogicResponse.success("success");
    }

    @PostMapping("/list")
    @ApiOperation(value = "获取banner列表", notes = "获取banner列表")
    public LogicResponse getBannerList(@RequestBody @Validated BannerQueryDTO bannerQueryDTO) {
        return LogicResponse.success(bannerService.getBannerList(bannerQueryDTO));
    }

    @PostMapping("/delete")
    @ApiOperation(value = "删除banner接口", notes = "删除banner接口")
    public LogicResponse delete(@RequestBody @Validated BannerIdDTO bannerIdDTO) {
        bannerService.delete(bannerIdDTO);
        return LogicResponse.success("success");
    }

    @PostMapping("/detail")
    @ApiOperation(value = "获取单个banner详情")
    public LogicResponse getBannerDetail(@RequestBody @Validated BaseIdDTO baseIdDTO) {
        return LogicResponse.success(bannerService.getBannerDetail(baseIdDTO));
    }

    @PostMapping("/add/readCount")
    @ApiOperation(value = "点击一次增加一次",notes = "点击一次增加一次")
    public LogicResponse addClickCount(@RequestBody @Validated BaseIdDTO baseIdDTO) {
        bannerService.addClickCount(baseIdDTO);
        return LogicResponse.success("success");
    }
}
